<template>
  <el-timeline>
    <!--
    timestamp: 标识时间戳
    placement: 时间戳展示位置
    -->
    <el-timeline-item
      v-for="item in chapterData"
      :key="item.id"
      :timestamp="item.timestamp"
      :hollow="true"
      :color="item.color"
    >
      <el-card>
        <h3>{{ item.content }}</h3>
      </el-card>
    </el-timeline-item>
  </el-timeline>
</template>

<script setup>
import { reqChapter } from '@/api/user.js'
import { ref, onMounted } from 'vue'
import { watchSwitchLang } from '@/utils/i18n'
const chapterData = ref([])
const getChapterData = async () => {
  chapterData.value = await reqChapter()
  chapterData.value.map((item) => {
    item.color = generateRandomColor()
    return item
  })
  function generateRandomColor() {
    const randomColor = Math.floor(Math.random() * 0xffffff).toString(16)
    // 确保颜色代码是6位的，通过在前面添加0来补齐
    return `#${randomColor.padStart(6, '0')}`
  }
}
onMounted(() => {
  getChapterData()
})
// 监听语言切换
watchSwitchLang(getChapterData)
</script>

<style lang="scss" scoped></style>
